package com.yuneec.fly.dialogs;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.yuneec.fly.R;

/**
 * Created by jw.gu on 2016/6/25.
 */
@SuppressLint("ValidFragment")
public class AmapOfflineDeleteDialog extends BaseDialogFragment {
    public static interface OnDeleteListener {
        public void onDelete();
    }

    public static interface OnCheckUpdateListener {
        public void onCheckUpdate();
    }

    private boolean showUpdate;
    private String name;
    private OnDeleteListener onDeleteListener;
    private OnCheckUpdateListener onCheckUpdateListener;

    public AmapOfflineDeleteDialog(String name, boolean showUpdate, OnDeleteListener onDeleteListener, OnCheckUpdateListener onCheckUpdateListener) {
        super();
        this.name = name;
        this.showUpdate = showUpdate;
        this.onDeleteListener = onDeleteListener;
        this.onCheckUpdateListener = onCheckUpdateListener;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        View view = inflater.inflate(R.layout.dialog_delete_amapoffline, container);
        final TextView name = (TextView) view.findViewById(R.id.nameTV);
        View checkUpdateBtn = view.findViewById(R.id.checkUpdateBtn);
        if (!showUpdate) {
            checkUpdateBtn.setVisibility(View.GONE);
        }
        name.setText(this.name);
        View.OnClickListener cancelListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        };
        view.findViewById(R.id.deleteBtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onDeleteListener != null) {
                    onDeleteListener.onDelete();
                }
            }
        });
        checkUpdateBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onCheckUpdateListener != null) {
                    onCheckUpdateListener.onCheckUpdate();
                }
            }
        });
        view.findViewById(R.id.cancelIV).setOnClickListener(cancelListener);
        return view;
    }
}
